<?php
/**
 * Date: 11/12/12
 * Time: 7:14 AM
 * User: Amitav Roy
 */
class Category extends CI_Controller{
	function __construct() {
		// Loading the constructor.
		parent::__construct();

		// This section required login.
		auth_user();

		// Loading the model on start
		$this->load->model('category_m');
	}

	/**
	 * Index page will not be used directly.
	 * Redirecting to the view page.
	 */
	function index() {
		redirect('category/view');
	}

	function view() {
		$data['pagetitle'] = 'Category / Sub Category page';
		$data['subheading'] = 'View the available categories and sub categories';
		// $data['scripts']['transaction'] = 'transaction';
		// $data['scripts']['dashboard'] = 'dashboard';
		$data['viewname'] = 'viewcattree_v.php';
		$data['viewdata'] = '';

		$this->load->view('master', $data);
	}
	
	/**
	 * This is the page for the form to add sub category by selecting the parent 
	 * term.
	 */
	function add() {
		$data['pagetitle'] = 'Add a Sub Category';
		$data['subheading'] = 'Add a sub category to the major category of expenses';
		$data['viewname'] = 'addsubcat_v.php';
		$data['viewdata'] = '';
		
		$this->load->view('master', $data);
	}
	
	/**
	 * This is the page which is doing the actual insert.
	 */
	function subcatsubmit() {
		if (isset($_POST) && $_POST['save'] == 'Save') {
			// Loading the model
			$this->load->model('category_m','cat');
			
			// Building the data
			$data['cid'] = $this->input->post('category');
			$data['name'] = $this->input->post('subcat');
			
			// Insert data through model
			$this->cat->save_sub_category($data);
			
			// Set the message for the user
			set_message('Your sub category is saved.');
			
			// Redirecting the user to the parent page
			redirect('category/add');
		}
		else {
			// Post data not present, redirect.
			redirect('category/add');
		}
	}
}

/* End of file category.php */
/* Location: ./application/controllers/category.php */